const hasOwnProperty = Object.prototype.hasOwnProperty;

function getClass(obj) {
  return Object.prototype.toString
    .call(obj)
    .slice(8, -1)
    .toLowerCase();
}

export function hasOwn(obj, prop) {
  return hasOwnProperty.call(obj, prop);
}

export function isArray(obj) {
  return Array.isArray(obj);
}

export function isEmptyArray(obj) {
  return obj.length === 0;
}

export function isEmptyObject(obj) {
  return JSON.stringify(obj) === '{}';
}

export function isPlainObject(obj) {
  return getClass(obj) === 'object';
}

function _formatDateText(value) {
  return value > 9 ? value : '0' + value;
}

export function formatDateTime(date) {
  date = date || new Date();
  const year = date.getFullYear();
  const month = _formatDateText(date.getMonth() + 1);
  const day = _formatDateText(date.getDate());

  const hours = _formatDateText(date.getHours());
  const minutes = _formatDateText(date.getMinutes());
  const seconds = _formatDateText(date.getSeconds());

  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
// camlize
export function camelize(value) {
  return value.replace(/\-([a-z])/g, (matches, $1) => {
    return $1.toUpperCase();
  });
}
// decamlize
export function decamelize(value) {
  return value.replace(/([A-Z])/g, (matches, $1) => {
    return '-' + $1.toLowerCase();
  });
}
// clone
export function clone(...rest) {
  // 可以满足浅拷贝
  return Object.assign({}, ...rest);
}
